using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for AuthenticationScriptsAdaptor.
	/// </summary>
	public class AuthenticationScriptsAdaptor : Adaptor, IRefreshable
	{
    private AuthenticationScriptCollection authenticationScripts;
		public AuthenticationScriptsAdaptor(AuthenticationScriptCollection authenticationScripts)
		{
      this.authenticationScripts = authenticationScripts;
		}

    public override string Text
    {
      get
      {
        return "Authentication Scripts";
      }
    }

    public override object Object
    {
      get
      {
        return authenticationScripts;
      }
    }

    public override Control GetRenderer()
    {
      AuthenticationScriptsControl control = new AuthenticationScriptsControl();
      control.LoadScripts(authenticationScripts);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override void AddChildren(TreeNode node)
    {
      if (authenticationScripts.GuestUserScript != null)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new AuthenticationScriptAdaptor(authenticationScripts.GuestUserScript));
        node.Nodes.Add(childNode);
      }

      foreach (AuthenticationScript script in authenticationScripts)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new AuthenticationScriptAdaptor(script));
        node.Nodes.Add(childNode);
      }      
    }

    public override int ImageIndex
    {
      get
      {
        return 31;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      authenticationScripts.Refresh();
    }

    #endregion
  }
}
